package frame.options.simulation.create.nodes;

import java.util.List;

import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import model.algorithms.nodesMapping.NodesMappingAlgorithm;

import com.nexes.wizard.WizardPanelDescriptor;

import frame.options.simulation.create.CreateSimulationWizard;
import frame.options.simulation.create.coordinated.CoordinatedDescriptor;
import frame.options.simulation.create.links.LinksDescriptor;

public class NodesDescriptor extends WizardPanelDescriptor implements ListSelectionListener
{
	public static final String IDENTIFIER = NodesDescriptor.class.getSimpleName();
	
	private NodesPanel nodesPanel;
	public NodesPanel getNodesMappingPanel(){ return this.nodesPanel; }
	public void setNodesMappingPanel( NodesPanel nodesPanel ){ this.nodesPanel = nodesPanel; }
	
	public NodesDescriptor( List< NodesMappingAlgorithm > nodesMappingAlgorithms )
    {
		this.setPanelDescriptorIdentifier( NodesDescriptor.IDENTIFIER );
		
    	this.setNodesMappingPanel( new NodesPanel( nodesMappingAlgorithms ) );
		this.getNodesMappingPanel().addListeners( this );
        this.setPanelComponent( this.getNodesMappingPanel() );
    }
	
	@Override
	public Object getBackPanelDescriptor()
	{
		return CoordinatedDescriptor.IDENTIFIER;
	}
    @Override
	public Object getNextPanelDescriptor()
    {
    	return LinksDescriptor.IDENTIFIER;
    }
    @Override
	public void aboutToDisplayPanel()
    {
    	this.getWizard().setNextFinishButtonEnabled( false );
    	
    	if( this.getNodesMappingPanel().getNodesMappingAlgorithmsList().getSelectedValuesList().size() == 1 )
    		this.getWizard().setNextFinishButtonEnabled( true );
    }
	
	@Override
	public void valueChanged( ListSelectionEvent listSelectionEvent )
	{
		this.getWizard().setNextFinishButtonEnabled( false );
		
    	if( this.getNodesMappingPanel().getNodesMappingAlgorithmsList().getSelectedValuesList().size() == 1 )
    	{
    		( (CreateSimulationWizard) this.getWizard() ).setNodesMappingAlgorithm( this.getNodesMappingPanel().getSelectedNodesMappingAlgorithm() );
    		this.getWizard().setNextFinishButtonEnabled( true );
    	}
	}
	
}